﻿using Digitalmes.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Digitalmes.Services.Hosted
{
    public class AppHostedService :BaseService, IHostedService
    {


        public AppHostedService(IServiceProvider serviceProvider) : base(serviceProvider)
        {

        }

        public async Task StartAsync(CancellationToken cancellationToken)
        {
            try
            {
                Log.Information("系统开始加载服务");
                await Task.Delay(1000);
                var app = GetService<AppService>();
                var config = GetService<IConfiguration>();
                var sys = config.GetSection("Sys").Get<SysConfig>();
                await app.StartLine(sys);
            }
            catch (Exception ex)
            {

               Log.Error("系统服务启动失败",ex);
            }

            
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            return Task.CompletedTask;
        }
    }
}
